import pandas as pd

# 创建示例DataFrame
df = pd.DataFrame({
    'name': ['Alice', 'Bob', 'Charlie'],
    'age': [25, 30, 35],
    'city': ['New York', 'London', 'Paris']
})

# 方法1:使用iterrows()遍历
for index, row in df.iterrows():
    print(f"Index: {index}, Name: {row['name']}, Age: {row['age']}, City: {row['city']}")

# 方法2:使用itertuples()遍历
for row in df.itertuples():
    print(f"Index: {row.Index}, Name: {row.name}, Age: {row.age}, City: {row.city}")